package iot.operation.service.impl;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.StringUtils;
import iot.operation.constant.Constants;
import iot.operation.domain.IotDeviceType;
import iot.operation.mapper.IotDeviceTypeMapper;
import iot.operation.service.IIotDeviceTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 设备大类Service业务层处理
 * 
 * @author lujw
 * @date 2022-06-09
 */
@Service
public class IotDeviceTypeServiceImpl implements IIotDeviceTypeService 
{
    @Autowired
    private IotDeviceTypeMapper iotDeviceTypeMapper;

    /**
     * 查询设备大类
     * 
     * @param id 设备大类主键
     * @return 设备大类
     */
    @Override
    public IotDeviceType selectIotDeviceTypeById(Long id)
    {
        return iotDeviceTypeMapper.selectIotDeviceTypeById(id);
    }

    /**
     * 查询设备大类列表
     * 
     * @param iotDeviceType 设备大类
     * @return 设备大类
     */
    @Override
    public List<IotDeviceType> selectIotDeviceTypeList(IotDeviceType iotDeviceType)
    {
        return iotDeviceTypeMapper.selectIotDeviceTypeList(iotDeviceType);
    }

    /**
     * 新增设备大类
     * 
     * @param iotDeviceType 设备大类
     * @return 结果
     */
    @Override
    public int insertIotDeviceType(IotDeviceType iotDeviceType)
    {
        iotDeviceType.setCreateTime(DateUtils.getNowDate());
		iotDeviceType.setDelFlag("0");
        return iotDeviceTypeMapper.insertIotDeviceType(iotDeviceType);
    }

    /**
     * 修改设备大类
     * 
     * @param iotDeviceType 设备大类
     * @return 结果
     */
    @Override
    public int updateIotDeviceType(IotDeviceType iotDeviceType)
    {
        iotDeviceType.setUpdateTime(DateUtils.getNowDate());
        return iotDeviceTypeMapper.updateIotDeviceType(iotDeviceType);
    }

    /**
     * 批量删除设备大类
     * 
     * @param ids 需要删除的设备大类主键
     * @return 结果
     */
    @Override
    public int deleteIotDeviceTypeByIds(Long[] ids)
    {
        return iotDeviceTypeMapper.deleteIotDeviceTypeByIds(ids);
    }

    /**
     * 删除设备大类信息
     * 
     * @param id 设备大类主键
     * @return 结果
     */
    @Override
    public int deleteIotDeviceTypeById(Long id)
    {
        return iotDeviceTypeMapper.deleteIotDeviceTypeById(id);
    }

    /**
     * 校验typeCode是否唯一
     *
     * @param iotDeviceType 设备类型
     * @return
     */
    @Override
    public String checkTypeCodeUnique(IotDeviceType iotDeviceType){
        Long typeId = StringUtils.isNull(iotDeviceType.getId()) ? -1L : iotDeviceType.getId();
        IotDeviceType info = iotDeviceTypeMapper.checkTypeCodeUnique(iotDeviceType.getTypeCode());
        if (StringUtils.isNotNull(info) && info.getId().longValue() != typeId.longValue())
        {
            return Constants.NOT_UNIQUE;
        }
        return Constants.UNIQUE;
    }
}
